var ajax = (function () {
    //框架


    //new document
    function toNewPage(data, callback) {
        request("/newPage", data, "POST", callback);
    }

    //new create register
    function createTable(data, callback) {
        request("/newCreate", data, "POST", callback);
    }

    //save register
    function save(data,callback){
        request("/save",data,"POST",callback);
    }

    //请求封装
    function request(url, data, method, callback) {
        console.log("开始请求", method, url, data)
        $.ajax({
            url: url,
            type: method ? method : "GET",
            data: data,
            dataType: 'json',
            success: function (result) {
                callback && callback(result);
                console.log("请求成功", method, url, data, result)
            },
            error: function (result) {
                console.log(result);
                console.error("请求失败", method, url, data)
            }
        });

    }

    return {
        toNewPage: toNewPage,
        createTable: createTable,
        save:save
    }
})();
